<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="道路编码" prop="roadId">-->
<!--        <el-input-->
<!--          v-model="queryParams.roadId"-->
<!--          placeholder="请输入道路编码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="道路名称" prop="roadName">-->
<!--        <el-input-->
<!--          v-model="queryParams.roadName"-->
<!--          placeholder="请输入道路名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="隧道编码" prop="tunnelId">-->
<!--        <el-input-->
<!--          v-model="queryParams.tunnelId"-->
<!--          placeholder="请输入隧道编码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="隧道名称" prop="tunnelName">
        <el-input
          v-model="queryParams.tunnelName"
          placeholder="请输入隧道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评定类别" prop="totalGrade">
<!--        查询参数 queryParams-->
        <el-select v-model="queryParams.totalGrade" placeholder="请输入隧道总体技术状况评定类别"  clearable >
          <el-option v-for="(item, index) in fieldtotalGrade" :key="index" :label="item.label"
                     :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="养护日期" prop="maintenanceDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.maintenanceDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择养护日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="养护频率" prop="maintenanceFrequency">-->
<!--        <el-input-->
<!--          v-model="queryParams.maintenanceFrequency"-->
<!--          placeholder="请输入养护频率"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="养护方案" prop="maintenanceScheme">-->
<!--        <el-input-->
<!--          v-model="queryParams.maintenanceScheme"-->
<!--          placeholder="请输入养护方案"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="养护机构" prop="maintenanceOrganization">-->
<!--        <el-input-->
<!--          v-model="queryParams.maintenanceOrganization"-->
<!--          placeholder="请输入养护机构"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="养护人员" prop="maintenancePerson">
        <el-input
          v-model="queryParams.maintenancePerson"
          placeholder="请输入养护人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="养护状态" prop="maintenanceCondition">
<!--        <el-input-->
<!--          v-model="queryParams.maintenanceCondition"-->
<!--          placeholder="请输入养护状态"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select v-model="queryParams.maintenanceCondition" placeholder="请输入养护状态"  clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in fieldmaintenanceCondition" :key="index" :label="item.label"
                     :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:allmaintenance:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:allmaintenance:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:allmaintenance:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:allmaintenance:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
<!--表的展示-->
    <el-table v-loading="loading" :data="allmaintenanceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录表编码" align="center" prop="allMaintenanceId" />
<!--      <el-table-column label="道路编码" align="center" prop="roadId" />-->
<!--      <el-table-column label="道路名称" align="center" prop="roadName" />-->
<!--      <el-table-column label="隧道编码" align="center" prop="tunnelId" />-->
      <el-table-column label="隧道名称" align="center" prop="tunnelName" />
      <el-table-column label="总体技术状况评定类别" align="center" prop="totalGrade" />
<!--      <el-table-column label="养护日期" align="center" prop="maintenanceDate" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.maintenanceDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="养护频率" align="center" prop="maintenanceFrequency" />-->
      <el-table-column label="养护方案" align="center" prop="maintenanceScheme" />
<!--      <el-table-column label="养护机构" align="center" prop="maintenanceOrganization" />-->
      <el-table-column label="养护人员" align="center" prop="maintenancePerson" />
      <el-table-column label="养护状态" align="center" prop="maintenanceCondition" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:allmaintenance:edit']"
          >修改</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['biz:allmaintenance:remove']"-->
<!--          >删除</el-button>-->
          <el-button
          size="mini"
          type="text"
          icon="el-icon-edit"
          @click="handleCheck(scope.row)"
          v-hasPermi="['civil:allmaintenance:edit']"
        >查看</el-button>
          <el-dropdown size="mini" >
                <span class="el-dropdown-link">
                  <i class="el-icon-d-arrow-right el-icon--right"></i>去完成
                </span>
            <el-dropdown-menu slot="dropdown">
          <div>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleDesign5(scope.row)"
              v-hasPermi="['biz:treatment:list']"
            >填写土建结构病害处治</el-button>
          </div>
              <div>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleDesign6(scope.row)"
                  v-hasPermi="['biz:cleaning:list']"
                >填写土建结构清洁表</el-button>
              </div>
              <div>
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleDesign4(scope.row)"
                  v-hasPermi="['biz:tjjgbywx:list']"
                >填写土建结构保养维修表</el-button>
              </div>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改养护方案计划对话框 -->
    <el-dialog :title="title" :visible.sync="openadd" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--        公路表：公路名称-->
        <el-form-item label="道路名称"  prop="roadName">
          <el-select v-model="form.roadName" placeholder="请选择道路名称">
            <el-option
              v-for="item in gongluList"
              :key="item.id + ''"
              :label="item.field2"
              :value="item.field2 + ''"
              :disabled="item.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--      公路表：根据公路名称确定公路编码-->
        <el-form-item label="道路编码" prop="roadId">
          <el-select v-model="form.roadId" placeholder="请选择道路编码">
            <el-option
              v-for="item in gongluList"
              :key="item.id + ''"
              :label="item.field1"
              :value="item.field1 + ''"
              :disabled="item.status == 1"
              v-if="item.field2 == form.roadName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="隧道编码" prop="tunnelId">
          <el-select v-model="form.tunnelId" placeholder="请选择隧道编码">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field1 + ''"
              :label="dict.field1"
              :value="dict.field1 + ''"
              v-if="dict.field22 == form.roadName"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--        隧道表：根据隧道编码确定隧道名称-->
        <el-form-item label="隧道名称" prop="tunnelName">
          <el-select v-model="form.tunnelName" placeholder="请选择隧道名称">
            <el-option
              v-for="dict in suidaoList"
              :key="dict.field2 + ''"
              :label="dict.field2"
              :value="dict.field2 + ''"
              v-if="dict.field1 == form.tunnelId"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="道路编码" prop="roadId">-->
<!--          <el-input v-model="form.roadId" placeholder="请输入道路编码" />-->
<!--        </el-form-item>-->
<!--&lt;!&ndash;        <el-form-item label="道路名称" prop="roadName">&ndash;&gt;-->
<!--&lt;!&ndash;          <el-input v-model="form.roadName" placeholder="请输入道路名称" />&ndash;&gt;-->
<!--&lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--        <el-form-item label="道路名称"  prop="roadName">-->
<!--          <el-select v-model="form.roadName" placeholder="请选择道路">-->
<!--            <el-option-->
<!--              v-for="item in gongluList"-->
<!--              :key="item.id + ''"-->
<!--              :label="item.field2"-->
<!--              :value="item.field2 + ''"-->
<!--              :disabled="item.status == 1"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--&lt;!&ndash;        <el-form-item label="隧道编码" prop="tunnelId">&ndash;&gt;-->
<!--&lt;!&ndash;          <el-input v-model="form.tunnelId" placeholder="请输入隧道编码" />&ndash;&gt;-->
<!--&lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--        <el-form-item label="隧道编码" prop="tunnelId">-->
<!--          <el-select v-model="form.tunnelId" placeholder="请选择隧道编码">-->
<!--            <el-option-->
<!--              v-for="dict in suidaoList"-->
<!--              :key="dict.field1 + ''"-->
<!--              :label="dict.field1"-->
<!--              :value="dict.field1 + ''"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="隧道名称" prop="tunnelName">-->
<!--          <el-input v-model="form.tunnelName" placeholder="请输入隧道名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="隧道总体技术状况评定类别" prop="totalGrade">-->
<!--          <el-input v-model="form.totalGrade" placeholder="请输入隧道总体技术状况评定类别" />-->
<!--        </el-form-item>-->
        <el-form-item label="评定类别" prop="totalGrade">
          <el-select v-model="form.totalGrade" placeholder="请输入隧道总体技术状况评定类别"  clearable :style="{width: '100%'}">
              <el-option v-for="(item, index) in fieldtotalGrade" :key="index" :label="item.label"
                         :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="养护日期" prop="maintenanceDate">
          <el-date-picker clearable
            v-model="form.maintenanceDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择养护日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="养护频率" prop="maintenanceFrequency">
          <el-input v-model="form.maintenanceFrequency" placeholder="请输入养护频率" />
        </el-form-item>
        <el-form-item label="养护方案" prop="maintenanceScheme">
          <el-input v-model="form.maintenanceScheme" placeholder="请输入养护方案" />
        </el-form-item>
        <el-form-item label="养护机构" prop="maintenanceOrganization">
          <el-input v-model="form.maintenanceOrganization" placeholder="请输入养护机构" />
        </el-form-item>
        <el-form-item label="养护人员" prop="maintenancePerson">
          <el-input v-model="form.maintenancePerson" placeholder="请输入养护人员" />
        </el-form-item>
        <el-form-item label="养护状态" prop="maintenanceCondition">
<!--          <el-input v-model="form.maintenanceCondition" placeholder="请输入养护状态" />-->
          <el-select v-model="form.maintenanceCondition" placeholder="请输入养护状态"  clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in fieldmaintenanceCondition" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 查看养护方案计划对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="道路编码" prop="roadId">
<!--          placeholder 属性提供可描述输入字段预期值的提示信息(hint)-->
          <el-input v-model="form.roadId"  />
        </el-form-item>
        <el-form-item label="道路名称" prop="roadName">
          <el-input v-model="form.roadName" />
        </el-form-item>
        <el-form-item label="隧道编码" prop="tunnelId">
          <el-input v-model="form.tunnelId"  />
        </el-form-item>
        <el-form-item label="隧道名称" prop="tunnelName">
          <el-input v-model="form.tunnelName" />
        </el-form-item>
        <el-form-item label="评定类别" prop="totalGrade">
          <el-input v-model="form.totalGrade"  />
        </el-form-item>
        <el-form-item label="养护日期" prop="maintenanceDate">
          <el-date-picker clearable
                          v-model="form.maintenanceDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="养护频率" prop="maintenanceFrequency">
          <el-input v-model="form.maintenanceFrequency"  />
        </el-form-item>
        <el-form-item label="养护方案" prop="maintenanceScheme">
          <el-input v-model="form.maintenanceScheme"  />
        </el-form-item>
        <el-form-item label="养护机构" prop="maintenanceOrganization">
          <el-input v-model="form.maintenanceOrganization"  />
        </el-form-item>
        <el-form-item label="养护人员" prop="maintenancePerson">
          <el-input v-model="form.maintenancePerson"  />
        </el-form-item>
        <el-form-item label="养护状态" prop="maintenanceCondition">
          <el-input v-model="form.maintenanceCondition"  />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import router from "../../../router";
import { listAllmaintenance, getAllmaintenance, delAllmaintenance, addAllmaintenance, updateAllmaintenance ,exportAllmaintenance,} from "@/api/biz/allmaintenance";
import { listSuidao } from "@/api/biz/suidao";
import { listGonglu } from "@/api/biz/gonglu";
import { exportJidiansheshiguzhangxuncha } from '@/api/biz/jidiansheshiguzhangxuncha'

export default {
  name: "Allmaintenance",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 养护方案计划表格数据
      allmaintenanceList: [],
      //隧道列表
      suidaoList: [],
      //道路列表
      gongluList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示增加或修改的弹出层
      openadd: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roadId: null,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        totalGrade: null,
        maintenanceDate: null,
        maintenanceFrequency: null,
        maintenanceScheme: null,
        maintenanceOrganization: null,
        maintenancePerson: null,
        maintenanceCondition: null
      },
      // 表单参数
      form: {},
      fieldtotalGrade: [{
        "label": "1类",
        "value": "1类"
      }, {
        "label": "2类",
        "value": "2类"
      },{
        "label": "3类",
        "value": "3类"
      }, {
        "label": "4类",
        "value": "4类"
      },{
        "label": "5类",
        "value": "5类"
      },
      ],

      fieldmaintenanceCondition: [{
        "label": "未养护",
        "value": "未养护"
      }, {
        "label": "养护中",
        "value": "养护中"
      },{
        "label": "已养护",
        "value": "已养护"
      },
      ],
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    listSuidao({}).then((response) => {
      this.suidaoList = response.rows;
    });
    listGonglu({}).then((response) => {
      this.gongluList = response.rows;
    });
  },
  methods: {
    /** 查询养护方案计划列表 */
    getList() {
      this.loading = true;
      listAllmaintenance(this.queryParams).then(response => {
        this.allmaintenanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.openadd = false;
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        allMaintenanceId: null,
        roadId: null,
        roadName: null,
        tunnelId: null,
        tunnelName: null,
        totalGrade: null,
        maintenanceDate: null,
        maintenanceFrequency: null,
        maintenanceScheme: null,
        maintenanceOrganization: null,
        maintenancePerson: null,
        maintenanceCondition: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.allMaintenanceId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openadd = true;
      this.title = "添加养护方案计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const allMaintenanceId = row.allMaintenanceId || this.ids
      getAllmaintenance(allMaintenanceId).then(response => {
        this.form = response.data;
        this.openadd = true;
        this.title = "修改养护方案计划";
      });
    },
    //填写保养维修
    handleDesign4(row) {
      this.$router.push({path: '/tjjgbywx/index'})

    },
    //填写去病害处治按钮
    handleDesign5(row) {
      router.push(
        {
          path: '/treatment/index',
          query: {
            roadid: row.roadId,
            roadname: row.roadName,
            tunnelid: row.tunnelId,
            tunnelname: row.tunnelName,
            maintenanceorganization: row.maintenanceOrganization,
          }
        })
    },
    //填写清洁
    handleDesign6(row) {
      router.push(
        {
          path: '/cleaning/index',
          query: {
            roadid: row.roadId,
            roadname: row.roadName,
            tunnelid: row.tunnelId,
            tunnelname: row.tunnelName,
            maintenanceorganization: row.maintenanceOrganization,
          }
        })
    },
    /** 查看按钮操作 */
    handleCheck(row) {
      this.reset();
      const allMaintenanceId = row.allMaintenanceId || this.ids
      getAllmaintenance(allMaintenanceId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看养护方案计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.allMaintenanceId != null) {
            updateAllmaintenance(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openadd = false;
              this.getList();
            });
          } else {
            addAllmaintenance(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openadd = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const allMaintenanceIds = row.allMaintenanceId || this.ids;
      this.$modal.confirm('是否确认删除养护方案计划编号为"' + allMaintenanceIds + '"的数据项？').then(function() {
        return delAllmaintenance(allMaintenanceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // /** 导出按钮操作 */
    // handleExport() {
    //   this.download('biz/allmaintenance/export', {
    //     ...this.queryParams
    //   }, `allmaintenance_${new Date().getTime()}.xlsx`)
    // },
    //
  /** 导出按钮操作 */
  handleExport() {
    const queryParams = this.queryParams;
    this.$modal
      .confirm("是否确认导出所有数据项？")
      .then(() => {
        this.exportLoading = true;
        return exportAllmaintenance(queryParams);
      })
      .then((response) => {
        this.download(response.msg);
        this.exportLoading = false;
      })
      .catch(() => {});
  },
  },

};
</script>
